﻿using System;
using System.Collections.Generic;
using System.Text;
using PassBag;
using NUnit.Framework;
using PassBag.Logic;

namespace TestPassBag {

    [TestFixture, Description ("Test the TestPasswordObjectComparer class")]
    public class TestPasswordObjectComparer {

        [Test, Description ("Test sort on id with PasswordObject Class")]
        public void TestSortId () {
            PasswordObjectComparer comparer = new PasswordObjectComparer ();
            List<PasswordObject> passwordObjectList = new List<PasswordObject> ();

            Guid guid1 = new Guid ("{CA761232-ED42-11CE-BACD-00AA0057B223}");
            Guid guid2 = new Guid ("{CA761232-ED42-11CE-BACD-00AA0057B224}");
            Guid guid3 = new Guid ("{DA761232-ED42-11CE-BACD-00AA0057B223}");
            Guid guid4 = new Guid ("{EA761232-ED42-11CE-BACD-00AA0057B223}");

            passwordObjectList.Add (new PasswordObject (guid3));
            passwordObjectList.Add (new PasswordObject (guid2));
            passwordObjectList.Add (new PasswordObject (guid4));
            passwordObjectList.Add (new PasswordObject (guid1));


            // Set comparaison method to DisplayName
            comparer.ComparisonMethod = PasswordObjectComparer.ComparisonType.Id;

            passwordObjectList.Sort (comparer);

            Assert.AreEqual (passwordObjectList[0].Id, guid1);
            Assert.AreEqual (passwordObjectList[1].Id, guid2);
            Assert.AreEqual (passwordObjectList[2].Id, guid3);
            Assert.AreEqual (passwordObjectList[3].Id, guid4);
        }

        [Test, Description ("Test sort on Username with PasswordObject Class")]
        public void TestSortUserName () {
            PasswordObjectComparer comparer = new PasswordObjectComparer ();
            List<PasswordObject> passwordObjectList = new List<PasswordObject> ();

            Guid guid1 = new Guid ("{CA761232-ED42-11CE-BACD-00AA0057B223}");
            Guid guid2 = new Guid ("{CA761232-ED42-11CE-BACD-00AA0057B224}");
            Guid guid3 = new Guid ("{DA761232-ED42-11CE-BACD-00AA0057B223}");
            Guid guid4 = new Guid ("{EA761232-ED42-11CE-BACD-00AA0057B223}");

            PasswordObject passObj1 = new PasswordObject (guid3);
            string user1 = "aaaaaaaaaa";
            passObj1.UserName = user1;

            PasswordObject passObj2 = new PasswordObject (guid1);
            string user2 = "aaaaaaaaab";
            passObj2.UserName = user2;

            PasswordObject passObj3 = new PasswordObject (guid4);
            string user3 = "daaaaaaaaa";
            passObj3.UserName = user3;

            PasswordObject passObj4 = new PasswordObject (guid2);
            string user4 = "daaaaaaaab";
            passObj4.UserName = user4;

            passwordObjectList.Add (passObj1);
            passwordObjectList.Add (passObj2);
            passwordObjectList.Add (passObj3);
            passwordObjectList.Add (passObj4);


            // Set comparaison method to DisplayName
            comparer.ComparisonMethod = PasswordObjectComparer.ComparisonType.UserName;

            passwordObjectList.Sort (comparer);

            Assert.AreEqual (passwordObjectList[0].UserName, user1);
            Assert.AreEqual (passwordObjectList[1].UserName, user2);
            Assert.AreEqual (passwordObjectList[2].UserName, user3);
            Assert.AreEqual (passwordObjectList[3].UserName, user4);
        }
    }
}
